package com.hjduan.spring.cloud.request.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;







import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hjduan.spring.cloud.request.service.City;
import com.hjduan.spring.cloud.request.service.RibbonService;


@RestController
public class RibbonController {
    @Autowired
    RibbonService ribbonService;
   
  
    @ApiOperation(value="获取city信息", notes="根据id获取city")// 使用该注解描述接口方法信息  
    @ApiImplicitParams({  
            @ApiImplicitParam(name = "id", value = "city表ID", required = true, dataType = "Long", paramType="path")  
    })// 使用该注解描述方法参数信息，此处需要注意的是paramType参数，
    @RequestMapping(value = "/ribbon/view/{id}")
    public City getRibbonCity(@PathVariable Integer id){
    	System.out.println(id);
        return ribbonService.getCityService(id);
    }

    @RequestMapping(value = "/timer")
    public void timer(){
    	Thread thread = new Thread(){
    		public void run(){
    			 Integer num = 0;
    			 Integer error = 0;
    			 while (true) {  
    				 num++;
    				 try {
    					String result = ribbonService.addCityService();
    					if(!result.equals("??"))
    						error ++;
    				 } catch (Exception e) {
						// TODO: handle exception
						error ++;
					}
    				
    				 if(num%10==0){		
    					 SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒SSS毫秒");			    
    					 System.out.println("总个数:"+num+";异常个数:"+error+";时间:"+sdf.format(new Date()));
    				 }
    				 
                     try {  
                         Thread.sleep(300);  
                     } catch (InterruptedException e) {  
                         e.printStackTrace();  
                     }  
                 }  
    		}
    	};
    	thread.start();
    }
}
